
const {ccclass, property} = cc._decorator;

let gameModelInstance

const colorLength = 5;
const changeTime = 5;

@ccclass
export default class gameModel extends cc.Component {

    private _gameType:number;//游戏类型 1.独奏 2.重奏 3.对战
    private _isGameOver:boolean;//游戏状态，false:进行中，true：游戏结束
    private _outsideTrianglePool:any;//缺口三角形对象池
    private _outSideTrianlePrefab:any;//缺口三角形预制件
    private _score:number;//得分
    private _colorType:number=0;//颜色类型
    private _overGamePrefab:any; //游戏结算界面预制件
    private _aloneGamePrefab:any;//独奏界面预制件
    private _mainScenePrefab:any;//主界面；
    
    static getInstance():gameModel{
        if(gameModelInstance){
            return gameModelInstance;
        }else{
            gameModelInstance = new gameModel()
            gameModelInstance.initModel(); 
            return gameModelInstance;
        }
    }

    private initModel(){
        console.log("加载gameModel");
        this.outsideTrianglePool=new cc.NodePool();
        let self=this;
        this.Score=0;
        cc.loader.loadRes("prefab/aloneScene/outSideTrianle", function (err, prefab) {
            console.error("outSideTrianle加载完成");
            self.outSideTrianlePrefab=prefab;
        });
        cc.loader.loadRes("prefab/aloneScene/overGame", function (err, prefab) {
            console.error("overGame加载完成");
            self._overGamePrefab=prefab;
        });
        cc.loader.loadRes("prefab/aloneScene/aloneGame", function (err, prefab) {
            console.error("aloneGame加载完成");
            self._aloneGamePrefab=prefab;
        });
        
        // this.ColorType=0
        this.schedule(function(){
            this.ColorType++
        },changeTime);
    }
    public set gameType(n:number){
        this._gameType=n;
    }
    public get gameType():number{
        return this._gameType;
    }
    public set isGameOver(b:boolean){
        this._isGameOver=b;
    }
    public get isGameOver():boolean{
        return this._isGameOver;
    }

    public set outsideTrianglePool(a:any){
        this._outsideTrianglePool=a;
    }
    public get outsideTrianglePool():any{
        return this._outsideTrianglePool;
    }

    public set outSideTrianlePrefab(p:any){
        this._outSideTrianlePrefab=p;
    }
    public get outSideTrianlePrefab():any{
        return this._outSideTrianlePrefab;
    }

    public set Score(n:number){
        this._score=n;
        (<any>window).CustomEventManager.trigger({type:"getScore",content:this._score})
    }

    public get Score():number{
        return this._score;
    }

    public set ColorType(n:number){
        this._colorType=n%colorLength;
        (<any>window).CustomEventManager.trigger({type:"changeColor",content:this._colorType})
    }
    public get ColorType():number{
        return this._colorType;
    }

    public get overGame():any{
        return this._overGamePrefab;
    }
    public get aloneGame():any{
        return this._aloneGamePrefab;
    }

    public set mainScene(a:any){
        this._mainScenePrefab=a;
    }

    public get mainScene():any{
        return this._mainScenePrefab;
    }
    // public jumpScene(sceneName:string,node:cc.Node){

    // }
}
